package com.zzl.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * Description：定时任务并行执行
 * Created by 朱正磊 on 2019-04-02 23:42
 */
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {

    @Override
    @SuppressWarnings("NullableProblems")
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        scheduledTaskRegistrar.setScheduler(taskExecutor());
    }

    /**
     * description：指定线程池大小
     * user 朱正磊
     * time 2019-04-02 23:51
     * @return 返回任务执行器（线程池）
     */
    @Bean(destroyMethod = "shutdown")
    @SuppressWarnings("ContextJavaBeanUnresolvedMethodsInspection")
    public Executor taskExecutor() {
        return Executors.newScheduledThreadPool(10);
    }

}
